package com.yang.contorller;


import com.yang.pojo.SysUser;
import com.yang.service.SysUserService;
import com.yang.utils.Constants;
import com.yang.utils.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by 杨天可 on 2022/3/29 10:57
 */
@RestController
@RequestMapping("/api/sysUser")
public class SysUserController {
    @Resource
    SysUserService sysUserService;

    /* 获取个人资料*/
    @GetMapping("/getSubject")
    public SysUser getSubject(){
        return sysUserService.getSubject();
    }

    /* 修改商家资料*/
    @PostMapping("/updateSysUser")
     public Map<String,Object> updateSysUser(@RequestBody SysUser sysUser){
        System.out.println(sysUser.getShopLogo());
        return sysUserService.updateSysUser(sysUser);
    }

    /* 删除商家（冻结状态）*/
    @GetMapping("/deleteSysUser")
    public Map<String,Object> deleteSysUser(@RequestParam("userId") Integer userId){
        return sysUserService.deleteSysUser(userId);
    }

    /* 根据id查找商家信息*/
    @GetMapping("/getUserById")
    public SysUser getUserById(@RequestParam("userId") Integer userId){
        return sysUserService.getUserById(userId);
    }

    /* 后台管理系统中生成二维码*/
    @GetMapping("/setQRCode")
    public Map<String,Object> setQRCode(@RequestParam("userId") Integer userId){
        return sysUserService.setQRCode(userId);
    }

    /* 获取商家列表+模糊查询*/
    @GetMapping("/getUserList")
    public Map<String,Object> getUserList(@RequestParam("userName") String userName,
                                     @RequestParam("phone") String phone,
                                     @RequestParam("startTime") String startTime,
                                         @RequestParam("endTime") String endTime,
                                          @RequestParam("pageSize") Integer pageSize,
                                          @RequestParam("currentPage") Integer currentPage){
        return sysUserService.getUserList(userName,phone,startTime,endTime,pageSize,currentPage);
    }

    /* 获取所有商家列表*/
    @GetMapping("/findAll")
    public List<SysUser> findAll(){
        return sysUserService.findAll();
    }
}
